package club.vann.kafka.mock.service.order;

import club.vann.kafka.mock.kafka.KafkaConsumer;
import club.vann.kafka.mock.kafka.KafkaTopicFactory;
import com.cyberx.lunyu.OrderEventOuterClass;
import com.google.protobuf.InvalidProtocolBufferException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/** 成交事件 */
@Service
@Slf4j
public class OrderEventService {
  public OrderEventService(KafkaConsumer kafkaConsumer) {
    kafkaConsumer.subTopic(KafkaTopicFactory.TRADE_EVENT_OUTPUT, "", this::sub);
  }

  private void sub(byte[] bytes) {
    try {
      OrderEventOuterClass.OrderEvent orderEvent = OrderEventOuterClass.OrderEvent.parseFrom(bytes);
      log.info("接收到消息：{}", orderEvent);
    } catch (InvalidProtocolBufferException e) {
      log.error(e.getMessage());
    }
  }
}
